package JavaSEAdvance.day09_HashSet;
import java.util.Collections;
import java.util.HashSet;
import java.util.Iterator;

/**
 * @author Xiao
 * @date 2021/7/27
 */
public class PersonTest {
    /**
     * 需求：
     *      定义Person类，属性name，age
     *      创建HashSet集合，存储三个Person对象
     *      分别使用迭代器和增强for遍历HashSet集合
     */
    public static void main(String[] args) {
        Person p1 = new Person("阿良", 24);
        Person p2 = new Person("左右", 25);
        Person p3 = new Person("平安", 21);
        HashSet<Person> hs = new HashSet<>();
        Collections.addAll(hs, p1, p2, p3);
        for (Person p : hs) {
            System.out.println(p);
        }
        System.out.println("------------");
        Iterator<Person> i = hs.iterator();
        while (i.hasNext()) {
            System.out.println(i.next());
        }
    }
}
